#ifndef LOGGER_H
#define LOGGER_H

#include <pthread.h>
#include <stdarg.h>
#include <unistd.h>
#include <stdio.h>


#ifdef LOGGING_INFO
#define LOGGING
#define LOG_INFO(...) LOG(INFO, ##__VA_ARGS__)
#define LOG_WARNING(...) LOG(WARNING, ##__VA_ARGS__)
#define LOG_ERROR(...) LOG(ERROR, ##__VA_ARGS__)
#define LOG_FATAL(...) LOG(FATAL, ##__VA_ARGS__)
#define LOG_PANIC(...) LOG(PANIC, ##__VA_ARGS__)
#endif


#ifdef LOGGING_WARNING
#define LOGGING
#define LOG_WARNING(...) LOG(WARNING, ##__VA_ARGS__)
#define LOG_ERROR(...) LOG(ERROR, ##__VA_ARGS__)
#define LOG_FATAL(...) LOG(FATAL, ##__VA_ARGS__)
#define LOG_PANIC(...) LOG(PANIC, ##__VA_ARGS__)
#define LOG_INFO(...) ;
#endif


#ifdef LOGGING_ERROR
#define LOGGING
#define LOG_ERROR(...) LOG(ERROR, ##__VA_ARGS__)
#define LOG_FATAL(...) LOG(FATAL, ##__VA_ARGS__)
#define LOG_PANIC(...) LOG(PANIC, ##__VA_ARGS__)
#define LOG_INFO(...) ;
#define LOG_WARNING(...) ;
#endif


#ifdef LOGGING_FATAL
#define LOGGING
#define LOG_FATAL(...) LOG(FATAL, ##__VA_ARGS__)
#define LOG_PANIC(...) LOG(PANIC, ##__VA_ARGS__)
#define LOG_INFO(...) ;
#define LOG_WARNING(...) ;
#define LOG_ERROR(...) ;
#endif


#ifdef LOGGING_PANIC
#define LOGGING
#define LOG_PANIC(...) LOG(PANIC, ##__VA_ARGS__)
#define LOG_INFO(...) ;
#define LOG_WARNING(...) ;
#define LOG_ERROR(...) ;
#define LOG_FATAL(...) ;
#endif

#define LOG_FORMAT "\tLOG %8s: in %20s:%4d in function %10s:\n"

#ifdef LOGGING

static FILE *log_file = stderr;

#define BUF_SIZE 1024
#define MSG_SIZE 1024


#define LOG(log_type, log_str, ...) \
		do { \
			fprintf(log_file, LOG_FORMAT log_str "\n", #log_type, __FILE__, __LINE__, __func__, ##__VA_ARGS__);\
			fflush(log_file);\
		} while(0)


#else

#define LOG_INFO(...) ;
#define LOG_WARNING(...) ;
#define LOG_ERROR(...) ;
#define LOG_FATAL(...) ;
#define LOG_PANIC(...) ;

#define LOG(log_type, log_str, ...) ;

#define LOGGER_INIT(path) ;
#define LOGGER_WAIT() ;
#define LOGGER_EXIT() ;

#endif


#endif //LOGGER_H
